package com.wc.codeforces.模拟.Choose_the_Different_Ones;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/5 9:57
 * @description https://codeforces.com/problemset/problem/1927/C
 */
public class Main {
    /**
     * 思路：
     * 题目相当于在每个数组中选择k / 2个数组成 1 ~ k的序列
     * 那我们贪心的知道, 如果两边都有, 就没有差别
     * 如果只有一边有, 那就是必选
     * 如果都没有, 那就不能满足
     * 特殊的就是只有一边有的
     * 那我们看只有一边有的需要选多少个, 如果小于等于k / 2, 可以证明一定能完成
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] a = new int[N], b = new int[N];
    static int n, m, k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            k = sc.nextInt();
            Arrays.fill(a, 1, k + 1, 0);
            Arrays.fill(b, 1, k + 1, 0);
            for (int i = 1; i <= n; i++) {
                int x = sc.nextInt();
                a[x]++;
            }
            for (int i = 1; i <= m; i++) {
                int x = sc.nextInt();
                b[x]++;
            }
            boolean res = true;
            int A = 0, B = 0;
            for (int i = 1; i <= k; i++) {
                if (a[i] == 0 && b[i] == 0) {
                    res = false;
                    break;
                } else if (a[i] == 0) B++;
                else if (b[i] == 0) A++;
            }
            if (res && A <= k / 2 && B <= k / 2) out.println("YES");
            else out.println("NO");
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
